#ifndef DEVICE_MDLE_H
#define DEVICE_MDLE_H

#include <QWidget>
#include <QTableWidget>
#include "../interface_mdle/interface_mdle.h"
#include "../../public_opt_subs/table_mdle/funciton_blck/QTableWidgetSave.h"
// --------------------------------------------
// 增加逻辑器件的访问
#define CONNECT_IN_RX(index) itf_in##index##_rx
#define CONNECT_OUT_RX(index) itf_out##index##_rx
#define CONNECT_IN_TX(index) itf_in##index##_tx
#define CONNECT_OUT_TX(index) itf_out##index##_tx

#define CONNECT_DEV(IDTX,IDRX,OUT,IN,M,N) \
    IDTX = connect(OUT, &device_mdle::itf_out##M##_tx, \
                   IN , &device_mdle::itf_in##N##_rx); \
    IDRX = connect(IN , &device_mdle::itf_in##M##_tx, \
                   OUT, &device_mdle::itf_out##N##_rx); \

#define CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,M,N) \
    switch (N) \
    { \
    case 1: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,1) break; \
    case 2: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,2) break; \
    case 3: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,3) break; \
    case 4: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,4) break; \
    case 5: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,5) break; \
    case 6: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,6) break; \
    case 7: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,7) break; \
    case 8: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,8) break; \
    case 9: CONNECT_DEV(IDTX,IDRX,OUT,IN,M,9) break; \
    default: break; \
    } \

#define CONNECT_DEVS_INOUT(IDTX,IDRX,OUT,IN,M,N) \
    switch (M) \
    { \
    case 1: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,1,N) break; \
    case 2: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,2,N) break; \
    case 3: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,3,N) break; \
    case 4: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,4,N) break; \
    case 5: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,5,N) break; \
    case 6: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,6,N) break; \
    case 7: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,7,N) break; \
    case 8: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,8,N) break; \
    case 9: CONNECT_DEVS_INNER(IDTX,IDRX,OUT,IN,9,N) break; \
    default: break; \
    } \

namespace Ui {
class device_mdle;
}

class device_mdle : public QWidget
{
    Q_OBJECT

public:
    explicit device_mdle(QWidget *parent = nullptr);
    ~device_mdle();

    // --------------------------------------------
    // 提供各个参数的获取途径
    QString    getDevName(); //! 获取器件名
    QString    getDevCode(); //! 获取器件编码
    QList<int> getSite(); //! 获取位置
    QList<int> getSize(); //! 获取大小
    QString    getHandle(); //! 获取器件句柄，进行唯一性访问

    QList<QString> getInputName(); //! 获取输入端口
    QList<QString> getOutputName(); //! 获取输出端口


    interface_mdle * getInputItf(int index = 0);
    interface_mdle * getOutputItf(int index = 0);

    void setDevName(QString   ); //! 获取器件名
    void setDevCode(QString   ); //! 获取器件编码
    void setHandle(QString   ); //! 获取器件编码

    void setSite( int x0, int y0, int x1, int y1); //! 获取位置
    // --------------------------------------------
    // 提供拷贝
    QList <QString> getDate(); //! 获取所有的器件数据
    void setDate(QList <QString>); //! 获取所有的器件数据

    // --------------------------------------------
    // 提供缓存
    void save(QString &fileName);
    void load(QString &fileName);

    // --------------------------------------------
    // 提供隐藏
    void hide_dev(bool en = true);
private:
    Ui::device_mdle *ui;
protected:
    QTableWidgetSave *table; //器件信息
public slots:
    void signal_itf_monitor_slot( QVariantList &); //! 信号监测
    // --------------------------------------------
    // 增加器件的IO的逻辑定义
signals: //直接在器件层次增加IO，子类只需要把信号连接到父类，就可以得到逻辑与图像的关联
    void itf_in1_rx( QVariantList &);
    void itf_in2_rx( QVariantList &);
    void itf_in3_rx( QVariantList &);
    void itf_in4_rx( QVariantList &);
    void itf_in5_rx( QVariantList &);
    void itf_in6_rx( QVariantList &);
    void itf_in7_rx( QVariantList &);
    void itf_in8_rx( QVariantList &);
    void itf_in9_rx( QVariantList &);

    void itf_in1_tx( QVariantList &);
    void itf_in2_tx( QVariantList &);
    void itf_in3_tx( QVariantList &);
    void itf_in4_tx( QVariantList &);
    void itf_in5_tx( QVariantList &);
    void itf_in6_tx( QVariantList &);
    void itf_in7_tx( QVariantList &);
    void itf_in8_tx( QVariantList &);
    void itf_in9_tx( QVariantList &);


    void itf_out1_tx( QVariantList &);
    void itf_out2_tx( QVariantList &);
    void itf_out3_tx( QVariantList &);
    void itf_out4_tx( QVariantList &);
    void itf_out5_tx( QVariantList &);
    void itf_out6_tx( QVariantList &);
    void itf_out7_tx( QVariantList &);
    void itf_out8_tx( QVariantList &);
    void itf_out9_tx( QVariantList &);

    void itf_out1_rx( QVariantList &);
    void itf_out2_rx( QVariantList &);
    void itf_out3_rx( QVariantList &);
    void itf_out4_rx( QVariantList &);
    void itf_out5_rx( QVariantList &);
    void itf_out6_rx( QVariantList &);
    void itf_out7_rx( QVariantList &);
    void itf_out8_rx( QVariantList &);
    void itf_out9_rx( QVariantList &);

};

#endif // DEVICE_MDLE_H
